package com.niji.littly_donkey_android.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.niji.littly_donkey_android.R;
import com.niji.littly_donkey_android.bean.Fans;
import com.niji.littly_donkey_android.bean.RelatedGoods;
import com.niji.littly_donkey_android.util.NetworkGlideImageLoader;
import com.niji.littly_donkey_android.view.CircleImageView;

import java.util.ArrayList;

public class RelatedGoodsAdapter extends ArrayAdapter<RelatedGoods> {


    private static final String TAG = "RelatedGoodsAdapter";

    private Context context;

    public RelatedGoodsAdapter(Context context, ArrayList<RelatedGoods> members)
    {
        super(context,0, members);
        this.context = context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        RelatedGoods relatedGoods = getItem(position);

        if(convertView == null)
        {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_related_goods_list, parent, false);
        }
        ImageView item_related_goods_img = convertView.findViewById(R.id.item_related_goods_img);
        ImageView item_related_goods_not_dafalut = convertView.findViewById(R.id.item_related_goods_not_dafalut);
        ImageView item_related_goods_defalut = convertView.findViewById(R.id.item_related_goods_defalut);
        TextView item_related_goods_title = convertView.findViewById(R.id.item_related_goods_title);
        TextView item_related_goods_city = convertView.findViewById(R.id.item_related_goods_city);
        TextView item_related_goods_id = convertView.findViewById(R.id.item_related_goods_id);
        TextView item_related_goods_comment = convertView.findViewById(R.id.item_related_goods_comment);
        TextView item_related_goods_price = convertView.findViewById(R.id.item_related_goods_price);


        //thumb.setImageBitmap(BitMap.getInstance().returnBitMap(u.getThumb()));

        if (relatedGoods.getUrl() != null){
            if (!relatedGoods.getUrl().equals("")){
                NetworkGlideImageLoader.getInstance().displayImage((Activity) context,relatedGoods.getUrl(),item_related_goods_img,0,0);
            }
        }
        item_related_goods_id.setText("" + relatedGoods.getId());
        item_related_goods_title.setText(relatedGoods.getName());
        item_related_goods_city.setText(relatedGoods.getCity());
        item_related_goods_comment.setText("评分" + relatedGoods.getComment());
        item_related_goods_price.setText("￥" + relatedGoods.getPrice() + "起");
        if(relatedGoods.isDefault()){
            item_related_goods_not_dafalut.setVisibility(View.INVISIBLE);
            item_related_goods_defalut.setVisibility(View.VISIBLE);
        }else {
            item_related_goods_not_dafalut.setVisibility(View.VISIBLE);
            item_related_goods_defalut.setVisibility(View.INVISIBLE);
        }

        return convertView;
    }

}



